package com.manage.server.controller.admin;

import com.manage.dto.UserRoleDTO;
import com.manage.dto.add.UserRoleAddDTO;
import com.manage.dto.update.UserRoleUpdateDTO;
import com.manage.result.PageResult;
import com.manage.server.service.UserRoleService;
import com.manage.vo.UserRoleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.manage.result.Result;

@RestController
@RequestMapping("/userRole")
public class UserRoleController {

    @Autowired
    private UserRoleService userRoleService;

    @PostMapping
    public Result add(@RequestBody UserRoleAddDTO userRoleAddDTO) {
        userRoleService.save(userRoleAddDTO);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        userRoleService.removeById(id);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody UserRoleUpdateDTO userRoleUpdateDTO) {
        userRoleService.updateById(userRoleUpdateDTO);
        return Result.success();
    }

    /**
     * 多项分类分页查询
     * @param userRoleDTO
     * @return
     */
    @PostMapping("/page")
    public PageResult<UserRoleVO> findUserRole(@RequestBody UserRoleDTO userRoleDTO) {
        return userRoleService.findUserRoleByPage(userRoleDTO);
    }
}